package com.addedstuff;

import java.util.ArrayList;
import java.util.Random;

import brianchen.util;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.boss.EntityDragon;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class Arenastarter extends Block 
{

	public void registerIcons(IconRegister iconReg)
	{
	    blockIcon = iconReg.registerIcon("Brianmodbase:arena starter.fw");
	}
	public Arenastarter(int par1) 
	{
		 super(par1,Material.dragonEgg);
		 setCreativeTab(CreativeTabs.tabBlock);
		// TODO Auto-generated constructor stub
	}
	public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
	{
		activated=true;//			   x     y     z
		par1World.scheduleBlockUpdate(par2, par3, par4 , blockID, 1);
	    return false;
	}
	
	/*
	 * Every 60 ticks or 3 seconds the spawner will spawn a creature
	 * (non-Javadoc)
	 * @see net.minecraft.block.Block#updateTick(net.minecraft.world.World, int, int, int, java.util.Random)
	 */
    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) 
    {
    	if(activated)
    	{
    		if (maxCreatures > creaturelist.size())
   		{
    			if (maxNumSkeleton > numSkeletonCreated)
    			{
    				EntitySkeleton Skeleton= new EntitySkeleton(par1World);//x,y,z
    				Vec3 vec = util.placeInRandomDirection(par2, par3, par4, 2);
    				Skeleton.setPosition(vec.xCoord, vec.yCoord, vec.zCoord);
     				Skeleton.setCurrentItemOrArmor(0, new ItemStack(Item.swordDiamond));
    				Skeleton.setCurrentItemOrArmor(1, new ItemStack(Item.bootsDiamond));
     				Skeleton.setCurrentItemOrArmor(2, new ItemStack(Item.legsDiamond));
     				Skeleton.setCurrentItemOrArmor(3, new ItemStack(Item.plateDiamond));
     				Skeleton.setCurrentItemOrArmor(3, new ItemStack(Item.helmetDiamond));
     				par1World.spawnEntityInWorld(Skeleton);
    				numSkeletonCreated++;
    				creaturelist.add(Skeleton);
    			}
    			else if (maxNumWither > numWitherCreated)
    			{
    				EntityWither Wither= new EntityWither(par1World);//x,y,z
    				Vec3 vec = util.placeInRandomDirection(par2, par3, par4, 2);
    				Wither.setPosition(vec.xCoord, vec.yCoord, vec.zCoord);
    				par1World.spawnEntityInWorld(Wither);
    				numWitherCreated++;
    				creaturelist.add(Wither);
    			}
    			else if (maxNumdragon > numdragonCreated)
    			{
    				EntityDragon Dragon = new EntityDragon(par1World);//x,y,z
    				Vec3 vec = util.placeInRandomDirection(par2, par3, par4, 30);
    				Dragon.setPosition(vec.xCoord, vec.yCoord+50, vec.zCoord);
    				par1World.spawnEntityInWorld(Dragon);
    				numdragonCreated++;
    				creaturelist.add(Dragon);
    			}
    		for (int i = creaturelist.size()-1;i >=0;i--)
    		{
    			if (creaturelist.get(i).isDead)
    			{
    				creaturelist.remove(i);
    			}
    		}
    		
    		par1World.scheduleBlockUpdate(par2, par3, par4 , blockID, 60);
    		
    		}
    		
    	}
    }
    private boolean activated = false;
    private int maxCreatures = 12;
    
    
    //Number of each creature type created 
    private int numSkeletonCreated = 0;
    private int numdragonCreated = 0;
    private int numWitherCreated = 0;
    
    //Maximum number of each creature type
    private int maxNumdragon = 1;
    private int maxNumWither = 1;
    private int maxNumSkeleton = 10;
    private ArrayList<EntityLiving> creaturelist=new ArrayList();
    

}